SRC = ${wildcard ./src/*.c}
OBJ = $(patsubst %c, %o, ${notdir $(SRC)})
BINDIR = ./bin
TARGET = pop

INCLUDE = -I ./include

CC ?= gcc

MODE = DEBUG
ifeq ($(MODE), DEBUG)
	CFLAGS := -g
	BIN := ./bin/debug
else
	CFLAGS := -O2
	BIN := ./bin
endif

.PHONY: all clean

all: $(OBJ)
	@echo start compiling... $^
	@$(CC) -o ${TARGET} $^
	mv *.o $(TARGET) -t ${BIN}
	@echo compiling success

$(OBJ): ${SRC}
	$(CC) $(INCLUDE) ${CFLAGS} -c $^

clean:clean-all clean-debug

clean-all:
	rm -rf ${wildcard ${BINDIR}/*.o} ${BINDIR}/${TARGET}

clean-debug:
	rm -rf ${wildcard ${BINDIR}/debug/*}
